<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php 
date_default_timezone_set("Asia/Kuala_Lumpur");	
include ("config.inc.php"); 
require ("engine/Sajax.php");

# Define the email validation function
function validate($stud_no) {
	$regex = '^[1][7][A-Z,a-z]{3}[0-9]{2}[A-Z,a-z]{1}[0-9]{3,4}$^';
    if (preg_match($regex,$stud_no)) {
        return " * Valid student number";
    } else {
        return " * Invalid student number";
    }
}

# Initialize Sajax
sajax_init();
# Export the server-side function to Sajax
sajax_export('validate');
# Handle client request
sajax_handle_client_request();

?>
<?php 
	include ("config/conn.php");
	$ad_check = 0;
	$user_check=0;
	$sid = session_id();
	$sql_check_session="SELECT session_username FROM session WHERE session_code='$sid'";
	$check_session=mysql_query($sql_check_session);
	$session=mysql_fetch_assoc($check_session);
	$ad_check=mysql_num_rows($check_session);
	if ($ad_check==1) {
		$id = $session['session_username'];
		$sql_get_name="SELECT ad_name FROM admin WHERE ad_no='$id'";
		$get_name=mysql_query($sql_get_name);
		$name=mysql_fetch_assoc($get_name);
		$who = $name['ad_name'];
	}
	if ($ad_check < 1) {
		$sql_check_usersession="SELECT u_session_username FROM user_session WHERE u_session_code='$sid'";
		$check_session2=mysql_query($sql_check_usersession);
		$session2=mysql_fetch_assoc($check_session2);
		$user_check=mysql_num_rows($check_session2);
		$id=$session2['u_session_username'];
		$sql_get_name="SELECT stud_name FROM student WHERE stud_no='$id'";
		$get_name=mysql_query($sql_get_name);
		$name=mysql_fetch_assoc($get_name);
		$who=$name['stud_name'];
		
	}
?>
<script type="text/javascript">
    <?php
        # Sajax toolkit generated javascript code
        sajax_show_javascript();
    ?>
    // Sends the email input to the server-side function
    // and throws the return value to showValidation.
    function js_validate(stud_no) 
	{
        x_validate(stud_no, showValidation);
    }
    // Prints the return value on the screen.
    // Changes the container's font color to green
    // if the return value is "Valid" and
    // to red if not.
    function showValidation(html) 
	{
        var element = document.getElementById('validation');
        element.innerHTML = html;
        if (html==' * Valid student number')
            element.style.color = 'green';
        else
            element.style.color = 'red';
    }
    </script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>E-Learning System ©</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="default.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
body {
	background-color: #000000;
	background-image: url("images/newstripe.png");
	background-repeat:repeat-xy;
}
-->
</style>
</head>
<body>
<div id="menu-wrap">
  <div id="menu">
    <ul>
		<li><a href="<?php echo get_server() . $location ."index.php"; ?>">Home</a></li>
	  <?php if ($user_check==1) { ?>
	    <li><a href="<?php echo get_server() . $location ."notes.php"; ?>">Download Notes </a></li>
	  <?php } ?>
	  <?php if ($user_check==1) { ?>
	    <li><a href="<?php echo get_server() . $location ."quiz_list.php"; ?>">Quiz </a></li>
	  <?php } ?>
		<li><a href="<?php echo get_server() . $location ."about_us.php"; ?>">About Us </a></li>
	  <?php if ($ad_check<1 && $user_check<1) { ?>
      	<li><a href="<?php echo get_server() . $location ."stud_reg.php"; ?>">Register </a></li>
	  <?php } ?>
	  <?php if ($ad_check<1 && $user_check<1) { ?>
      	<li><a href="<?php echo get_server() . $location ."login.php"; ?>">Login </a></li>
	  <?php } ?>
	  <?php if ( $ad_check >= 1 ) { ?>
		<li><a href="<?php echo get_server() . $location ."admin/admin.php"; ?>">Admin Control Panel </a></li>
	  <?php } ?>
	  <?php if ($user_check==1) { ?>
	    <li><a href="<?php echo get_server() . $location ."profile.php"; ?>">Profile </a></li>
	  <?php } ?>
	  <?php if ($user_check==1) { ?>
	    <li><a href="<?php echo get_server() . $location ."stat_detail.php"; ?>">User Stats </a></li>
	  <?php } ?>
    </ul>
  </div>
</div>
<div id="header">
</div><center>
<?php	if ($ad_check>0 || $user_check>0) {?>
  	<table width="780" border="0">
    <tr>
      <td width="634"><?php echo "&nbsp;&nbsp;<font color=\"red\">Welcome, <B>" .$who. "<B></font>";
	  ?></td>
      <td width="136" colspan="3"><div align="right"><?php echo "<a href=\"".$baseURL . $location . "logout.php\">Logout</a>&nbsp;&nbsp;"; ?></div></td> 
    </tr>
    <tr>
      <td colspan="4"><hr /></td>
      </tr>
  	</table>
  	<?php } ?></center>